import { TrophyFilled } from "@ant-design/icons"
import { deleteOne, loadClientInfo, saveOne,updateOne,select,selectItinerary} from "./service"

export default{
    namespace:'clientInfo',
    state:{
        list:[],
        current:{},
        itinerary:[],
        showEdit:false,
        isEdit:false,
        showPop:false,
        showSearch:false,
        showItinerary:false
    },
    effects:{
        *loadData({},{call,put}:any){
            const res=yield call(loadClientInfo)
            console.log(res)
            yield put({
                type:'save',
                payload:{
                    list:res.data,
                    showEdit:false,
                    isEdit:false,
                    showPop:false
                }
            })
        },
        *insert({payload}:any,{call,put}:any){
            yield call(saveOne,payload)
            yield put({
                type:'loadData',
                payload:{}
            })
        },
        *update({payload}:any,{call,put}:any){
          yield call(updateOne,payload.id,payload.data)
          yield put({
            type:'loadData',
            payload:{}
          })
        },
        *delete({payload}:any,{call,put}:any){
            yield call(deleteOne,payload.id,payload.data)
            yield put({
              type:'loadData',
              payload:{}
            })
          },
          *search({payload}:any,{call,put}:any){
            const res=yield call(select,payload.data)
            yield console.log(res)
            yield put({
                type:'save',
                payload:{
                    list:res.data,
                    showSearch:false
                }
            })
        },
        *showItinerary({payload}:any,{call,put}:any){
            const res=yield call(selectItinerary,payload.data)
            yield put({
                type:'save',
                payload:{
                    itinerary:res.data,
                    showItinerary:true
                }
            })
        }
    },
    reducers:{
        save(state:any,{payload}:any){
            return{...state,...payload}
        }
    }
}